<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(listIds)"
    okText="是"
    cancelText="否"
  >
    <a href="#">删除</a>
  </a-popconfirm>
</template>

<script>
import {getGoods, remove} from '@/api/basic/goodsList'
import {removeGoods} from '@/api/basic/goods'
export default {
  props: {
    listIds: {
      type: String
    }
  },
  data () {
    return {
      title: '确定要删除这' + this.listIds.split(',').length + '条记录吗？',
      goodsData: ''
    }
  },
  watch: {
    listIds: function (val) {
      this.title = '确定要删除这' + val.split(',').length + '条记录吗？'
    }
  },
  methods: {
    handleSubmit (listIds) {
      getGoods({ 'listIds': listIds })
        .then(res => {
          if (res.message !== 'error') {
            this.goodsData = res.result
            console.log("获得ids和data")
            console.log(this.goodsData)
            let ids = []
            for (let i = 0; i < this.goodsData.length; i++) {
              this.nft2(this.goodsData[i].goodsId, this.goodsData[i].owner)
              ids.push(this.goodsData[i].goodsId)
            }
            removeGoods({ 'ids': ids.join(',')})
              .then(res => {
                if (res.message !== 'error') {
                  // this.$emit('ok')
                } else {
                  this.$message.error('操作失败！')
                }
              })
          } else {
            this.$message.error('操作失败！')
          }
        })
      console.log(12333)
      console.log(listIds)
      remove({ 'listIds': listIds })
        .then(res => {
          if (res.message !== 'error') {
            this.$emit('ok')
          } else {
            this.$message.error('操作失败！')
          }
        })
    },
    nft2 (goodsIds, userAddress) {
      console.log('nft')
      console.log(goodsIds)
      // 删除作品, 查出来的Id=0就表示已经被删了，需要把返回数组中的0过滤掉。
      var result = this.$root.myContractInstance.burn(goodsIds, userAddress, {from: this.$root.userUrl, gas: 2000000})
      return result
    }
  }
}
</script>
